//
//  DZViewController.swift
//  Swift微博
//
//  Created by 董筱泽 on 16/10/22.
//  Copyright © 2016年 董筱泽. All rights reserved.
//

import UIKit

class DZViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 实例化 tabbar
        let tabBar = DZTabBar()
        // 02 闭包的实例化
        tabBar.closure = {
            // 04 接收回调
            print("在外面监听撰写按钮点击")
        }

        // 通过 kvc 给计算型属性赋值
        setValue(tabBar, forKey: "tabBar")
        addChildViewController(vc: DZHomeController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(vc: DZMessageController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(vc: DZDiscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(vc: DZProfileController(), title: "我", imgName: "tabbar_profile")
        
    }

    func addChildViewController(vc: UIViewController, title: String, imgName: String){
        vc.title = title
        // 设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        
        vc.tabBarItem.title = title
        vc.tabBarItem.image = UIImage(named: imgName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let vcNav = DZNavigationController(rootViewController: vc)
        addChildViewController(vcNav)
    }
    
    
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    
}
